<?php
/**
 * 用户表数据操作层
 * @author yangchao
 * @package user
 * @copyright yangchao
 * @version 1.0
 * @code-encode utf-8
 * @data-encode 2011-01-17
 */
define("CACHE_PREFIX_USER","_user_read_");
class db_user_read extends db_base {
    
	var $table_name = "user_read";
	
	function db_user_read()
	{
		parent::db_base();
	}
	
	/**
	 * 前台取用户信息
	 * @param $uid
	 */
	function get_user_read_item_by_uid($uid)
	{
		$uid = intval($uid);
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_USER."get_user_read_item_by_uid_{$uid}";
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$content = $this->get_alllist($this->table_name,1,1,"","uid='{$uid}'");
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}

	
	
	
	
		
	
	/**
	 * 用户注册
	 * @param $user_name
	 * @param $password
	 */
	function insert_user_read($uid)
	{
		// 插入数据
		
		$ary["uid"] = $uid;
		$ret = $this->insert($this->table_name, $ary);
		

		return $ret;
	}
	
	
	//更新用户信息
	function update_user_read_by_uid($uid,$read_at_id=0,$read_fans_id=0,$message_time="")
	{
		$ary = array();

		if($read_at_id)
		{
			$ary["read_at_id"] = $read_at_id;
		}
	
		if($read_fans_id)
		{
			$ary["read_fans_id"] = $read_fans_id;
		}
		if($message_time)
		{
			$ary["message_time"] = $message_time;
		}
		$uid = intval($uid);
		$where = "uid = $uid";
		
		
		$ret = $this->update($this->table_name, $ary,$where);
		if ($ret)
		{
			$memcache = mem_cache::get_instance();
			$key = CACHE_PREFIX_USER."get_user_read_item_by_uid_{$uid}";
			$memcache->delete($key);
		}
		else
		{
			return false;
		}


		return $ret;
		
		
		
	}
	
	
}



